<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>setup与渲染函数一起使用</title>
</head>

<body>
    <div id="app">
        <p>person.name:{{person.name}}</p>
        <p>person.sex:{{person.sex}}</p>
        <input type="button" value="修改性别" @click="changeSex">
        <hr/>
        <p>{{person.name}}的wife:</p>
        <p>年龄：{{person.wife.age}}</p>
        <input type="button" value="修改wife的年龄" @click="changeWifeAge"> 
    </div>
</body>
<script src="./js/vue.global.js"></script>
<script>

    const { createApp, ref, onMounted,h,reactive } = Vue

  
    const app = createApp({
        setup(){

            let sourceObj = {
                name:"李晨光",
                sex:"男",
                wife:{
                    name:"田宝",
                    age:16
                }
            }
           
           let person = reactive(sourceObj);//reactive()使用了proxy进行包裹。           

            console.log("person",person);//person是proxy对象。
            console.log("person.name",person.name);
            
            function changeSex(){
                person.sex = "女";
            }

            function changeWifeAge(){
                person.wife.age++;
            }

            return {
                person,
                changeSex,
                changeWifeAge
            }
        }
    })



    app.mount('#app')
</script>

</html>